<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
	/**
	 功能名称:修改学期功能
	 @author:
	 **/
%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>修改学期</title>
  <link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
  <script src="<%=path%>/dwr/engine.js"></script>
  <script src="<%=path%>/dwr/util.js"></script>
  <script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
  <script language="javascript" src="<%=path %>/js/syAjax.js"></script>
  <script type="text/javascript">
  		String.prototype.len=function(){		
		    var len = 0;
		    for (var i = 0; i < this.length; i++) {      
		        if (this.charCodeAt(i) > 255 || this.charCodeAt(i)<0) len += 2; else len ++;      
		    }      
			return len;
		}
  		var chkschoolTermResult=false;
	   function getSchoolTermCallBack(schoolTerm) {
	   	    var value=document.getElementById("schoolTermValue").value;
	        var schoolTermId=document.getElementById("schoolTermId").value;
		  	var schoolTermName=document.getElementById("schoolTermName");
        if(schoolTerm){  //2012-8-1314 闷男 返回值为true说明没有找到
            syAjax.request("post","updateSchoolTermyearAndSchoolTermAction.action","schoolTerm.name="+schoolTermName.value+"&schoolTerm.schoolTermValue="+value+"&schoolTerm.schoolTermId="+schoolTermId,{success:initSuccessResult,fail:onFail,type:'plain'});
         } else {
          	alert("该学期值存在，请确保学期值唯一！");
         }
        }  
        function isSchoolTermValueExsit(){		//2013-04-11-14 闷男 ajax 是异步的，在doUpdate中提交无法正确检测学期值的唯一性 
	        var value=document.getElementById("schoolTermValue").value;
	        var schoolTermId=document.getElementById("schoolTermId").value;
		  	var schoolTermName=document.getElementById("schoolTermName");
        	if(value !="${requestScope.SchoolTermById.schoolTermValue }"){
        		shiyueDwr.isSchoolTermValueExsit(value,getSchoolTermCallBack);
        	}else {
        		syAjax.request("post","updateSchoolTermyearAndSchoolTermAction.action","schoolTerm.name="+schoolTermName.value+"&schoolTerm.schoolTermValue="+value+"&schoolTerm.schoolTermId="+schoolTermId,{success:initSuccessResult,fail:onFail,type:'plain'});
        	}
        }
      
      
      function doUpdate(){
      var schoolTermId=document.getElementById("schoolTermId").value;
	  var schoolTermName=document.getElementById("schoolTermName");
	  var schoolTermValue=document.getElementById("schoolTermValue");
	  if(schoolTermName.value==""){
	    alert("学期名称不能为空！");
	    schoolTermName.focus();
	    return;
	  }else if(schoolTermValue.value==""){
	    alert("学期值不能为空！");
	    schoolTermValue.focus();
	    return;
	  }else if(!/^\d*$/.test(schoolTermValue.value)){
	    alert("你输入的学期值格式不符合要求！");
	    schoolTermValue.select();
        return;
	  
	  }else{
	    isSchoolTermValueExsit();
	  }
	}
	
	function initSuccessResult(data){
		window.returnValue=data;
		window.close();
	}
	</script>
  </head>
  <body bgcolor="#ECE9D8">
  <form action="" method="post">
    <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" align="left" valign="bottom" bgcolor="#ECE9D8" class="f_8">&nbsp;&nbsp;&nbsp;&nbsp;注：<span class="f_11">*</span>为必填项</td>
  </tr>
  <tr>
    <td height="12" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="top" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="30" align="right" class="f_6"><!-- <span class="f_11">*</span> --> 学期值：</td>
        <td align="left">
        	<select name="schoolTerm.schoolTermValue" style="width:155px;" onchange="changeSchoolTermValue(this);" disabled="disabled">
        		<option value="${requestScope.SchoolTermById.schoolTermValue }">${requestScope.SchoolTermById.schoolTermValue }</option>        		
        	</select>
        <input type="hidden" name="schoolTerm.schoolTermValue" value="${requestScope.SchoolTermById.schoolTermValue }" id="schoolTermValue"/>
        <input type="hidden" name="schoolTerm.schoolTermId" value="${requestScope.SchoolTermById.schoolTermId }" id="schoolTermId"/>
        </td>
      </tr>
	 <tr>
        <td width="25%" height="30" align="right" class="f_6"><span class="f_11">* </span>学期名称：</td>
        <td width="75%" align="left">
        <input type="text" name="schoolTerm.name" value="${requestScope.SchoolTermById.name }" id="schoolTermName" maxlength="25"/>
        </td>
      </tr>
 
    
     

      
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="55" align="center" valign="middle" bgcolor="#ECE9D8"><input type="button" value="提 交" onclick="doUpdate();"/></td>
  </tr>
</table>
</form>
  </body>
</html>
